# keybindings.py

def setup_keybindings(root, on_button_click, backspace, evaluate_expression):
    """
    绑定全局按键：
      - 回车 → evaluate_expression()
      - 退格 → backspace()
      - 数字/运算符/括号 → on_button_click(char)
    """
    def _on_key(event):
        if event.keysym == 'Return':
            evaluate_expression()
        elif event.keysym == 'BackSpace':
            backspace()
        elif event.char in '0123456789.+-*/^()':
            on_button_click(event.char)
        # 其它按键忽略

    root.bind_all('<Key>', _on_key)
